package com.xiaohudie.JUC;

import lombok.SneakyThrows;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.RecursiveTask;

/**
 * @Author xiao hu die
 * @Date 2022/1/16 0:57
 * @Version 1.0
 */
/**异步回调*/
public class Thread17 {
 @SneakyThrows
 public static void main(String[] args) {
/**异步调用 没有返回值*/
  CompletableFuture<Void> completableFuture =CompletableFuture.runAsync(()->{
   System.out.println(Thread.currentThread().getName()+"");
  });
  completableFuture.get();
  /**异步调用有返回值*/
  CompletableFuture<Integer> objectCompletableFuture = CompletableFuture.supplyAsync(()->{
   System.out.println(Thread.currentThread().getName()+"2222");
   int a=1/0;
   return 1024;
  });
  objectCompletableFuture.whenComplete((t,u)->{
   System.out.println("----t"+t);
   System.out.println("----u"+u);
  }).get();
 }
}
